Skip to content

Async function execution internals#1355

Open
TristonianJones wants to merge 4 commits into
cel-expr:masterfrom
TristonianJones:async-internals
Open

Async function execution internals#1355
TristonianJones wants to merge 4 commits into
cel-expr:masterfrom
TristonianJones:async-internals

Conversation

@TristonianJones

Copy link
Copy Markdown
Collaborator

Internal support for async function evaluation.

  • Declaration support with guard functions just like sync functions
  • The framework manages async function launches according to configurable concurrency limits
  • Async functions are provided the context.Context object and expected to block
    until a result is available and return it. The framework manages go routines

The implementation supports minimal call deduplication logic which users
will be able to extend with functionality introduced into later PRs.

@TristonianJones TristonianJones requested a review from l46kok June 22, 2026 22:35
Comment thread interpreter/async.go
Comment thread interpreter/async.go Outdated
Comment thread interpreter/async_test.go
Comment thread interpreter/async.go
@TristonianJones

Copy link
Copy Markdown
Collaborator Author

PTAL, thanks for the detailed review. I also added a NaN case to the async function call equality check.

Comment thread interpreter/async.go
Comment thread interpreter/async.go
Comment thread interpreter/async.go
go func() {
if semaphore != nil {
// Release the concurrency slot when this call finishes or is cancelled.
defer func() { <-semaphore }()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to also release the semaphore right before sending to the completion channel? defer runs at the very end of the goroutine right? If the semaphore is at capacity, there might be a small window where the next async call is rejected because defer hasn't ran.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we do. The completions signal indicates when a result is ready for re-evaluation (this will be more obvious in later PRs). The idea is that a batch of results are being accumulated and some logic is trying to decide whether to wait for all pending completions, a certain number of results, or a certain amount of time. The semaphore release at the end is the right thing to do since it should block until the decision about whether re-evaluate is made.

Comment thread interpreter/async.go
Comment thread interpreter/async.go Outdated
@TristonianJones

Copy link
Copy Markdown
Collaborator Author

PTAL and let me know what you think regarding the last open comment about the semaphore

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants